﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache">  <!-- HTTP 1.1 -->
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">  <!-- HTTP 1.0 -->
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/> <!--优先级：极速模式，兼容模式，IE模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>扬州房产测绘业务管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../../css/common.css">
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.min.js"></script>
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../libs/thUtil.js"></script>
    <script type="text/javascript" src="../../libs/valid.js"></script>
    <style>
        .bar-btn {
            margin-top: 20px;
            margin-bottom: 10px;
        }

        div.divider {
            clear: both;
            display: block;
            overflow: hidden;
            width: auto;
            height: 1px;
            padding: 4px 0 0 0;
            margin-bottom: 30px;
            border-style: dotted;
            border-width: 0 0 1px 0;
            border-color: #b8d0d6;
        }

        .btn-primary {
            color: #ffffff;
            text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
            background-color: #006dcc;
            *background-color: #0044cc;
            background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
            background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
            background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
            background-image: -o-linear-gradient(top, #0088cc, #0044cc);
            background-image: linear-gradient(to bottom, #0088cc, #0044cc);
            background-repeat: repeat-x;
            border-color: #0044cc #0044cc #002a80;
            border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0044cc', GradientType=0);
            filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
        }

        .btn-primary:hover {
            background-color: #0044cc;
            border-color: #0044cc #0044cc #002a80;
            border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
        }

        .btn-danger {
            color: #ffffff;
            text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
            background-color: #da4f49;
            *background-color: #bd362f;
            background-image: -moz-linear-gradient(top, #ee5f5b, #bd362f);
            background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ee5f5b), to(#bd362f));
            background-image: -webkit-linear-gradient(top, #ee5f5b, #bd362f);
            background-image: -o-linear-gradient(top, #ee5f5b, #bd362f);
            background-image: linear-gradient(to bottom, #ee5f5b, #bd362f);
            background-repeat: repeat-x;
            border-color: #bd362f #bd362f #802420;
            border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b', endColorstr='#ffbd362f', GradientType=0);
            filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
        }

        .btn-danger:hover {
            background-color: #bd362f;
            border-color: #bd362f #bd362f #802420;
            border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
        }

        .btn-normal {
            color: #141414;
            background-color: #ffffff;
            *background-color: #ffffff;
            background-image: -moz-linear-gradient(top, #ffffff, #ffffff);
            background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#ffffff));
            background-image: -webkit-linear-gradient(top, #ffffff, #ffffff);
            background-image: -o-linear-gradient(top, #ffffff, #ffffff);
            background-image: linear-gradient(to bottom, #ffffff, #ffffff);
            background-repeat: repeat-x;
            border-color: #ffffff #ffffff #b8b5af;
            border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b', endColorstr='#ffbd362f', GradientType=0);
            filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
        }

        .btn-normal:hover {
            color: #ffffff;
            background-color: #B8D0D6;
            border-color: #ffffff #ffffff #b8b5af;
        }

        .text-info {
            color: #3a87ad;
            padding-left: 5px;
        }

        table tr td {
            padding-bottom: 20px;
        }
    </style>
    <script type="text/javascript">
        var count = 0;
        $(function () {
            if (UrlParm.hasParm('text')) {
                $('h1').html(UrlParm.parm('text'));
            }

            ajax.initData();
            ajax.details();
            ajax.bindClick();
        });
        var ajax = {
            details: function () {
                Network.connect(window.api.thSysNavigationSelectView, "POST", {id: UrlParm.parm('id')}, function (res) {
                    if (ResponseCode.OK === res.code) {
                        ajax.setFormVal(res.data);
                    }
                })
            },
            setFormVal: function (data) {
                var tds = $("#form td");
                if (data) {
                    $('input[name="pcode"]').val(data.pcode);
                    $('input[name="id"]').val(data.id);
                } else {
                    $('input[name="pcode"]').val("");
                    $('input[name="id"]').val("");
                }
                tds.each(function () {
                    var inputs = $(this).find("input");
                    inputs.each(function () {
                        if ($(this).hasClass("easyui-textbox textbox-f")) {
                            var id = $(this).attr("id");
                            var val;
                            if (data) {
                                val = data[id] != null ? data[id] : 0;
                            } else {
                                val = 0;
                            }
                            switch (id) {
                                case "state":
                                    $("#state").combobox("setValue", val);
                                    break;
                                case "enable":
                                    $("#enable").combobox("setValue", val);
                                    break;
                                case "orderNo":
                                    $('#orderNo').numberspinner('setValue', val);  // 设置值
                                    break;
                                default:
                                    $("#" + id).textbox("setValue", val !== 0 ? val : "");
                                    break
                            }
                        }
                    });
                })
            },
            initData: function () {
                // $(".box").text( UrlParm.parm("code"));
                //是否禁用
                $('#state').combobox({
                    data: i18n.state,
                    valueField: 'id',
                    textField: 'text'
                });
                //是否展开
                $('#enable').combobox({
                    data: i18n.enable,
                    valueField: 'id',
                    textField: 'text'
                });
                //排序
                $('#orderNo').numberspinner({
                    min: 1,
                    max: 100,
                    editable: false
                }).numberspinner("setValue", 1);
                //默认菜单图样
                $('#iconCls').textbox("setValue", "icon-menu-default");
                //上级菜单
                $('#pname').textbox(({
                    icons: [{
                        iconCls: 'icon-add',
                        handler: function () {
                            ajax.showDialog();
                        }
                    }]
                }));
            },
            bindClick: function () {

                //绑定点击事件
                $('#addTopMenu').linkbutton({
                    onClick: function () {
                        $('.bar-btn').empty().html("<h4><p class=\"text-info\">添加顶级菜单</p></h4>");
                        ajax.setFormVal();
                        ajax.initData();
                        $("#pname").textbox("disable", true).textbox("setValue", "顶级");
                        $("#pcode").val("bar");
                    }
                });

                $('#addChildMenu').linkbutton({
                    onClick: function () {
                        var parentName = $("#name").textbox("getValue");
                        $('.bar-btn').empty().html("<h4><p class=\"text-info\">" + parentName + "-添加下级菜单</p></h4>");
                        // ajax.setFormVal();
                        // ajax.initData();
                        // $("#pname").textbox("disable", true).textbox("setValue","顶级");
                        // $("#pcode").val("bar");
                    }
                });

                $('#delete').linkbutton({
                    onClick: function () {
                        Tools.confirm('是否确定删除？', function (result) {
                            if (result) {
                                Network.connect(window.api.thSysNavigationDeleteView, "POST", {id: UrlParm.parm('id')}, function (res) {
                                    if (res.code === ResponseCode.OK) {
                                        Tools.show(res.message);
                                        parent.location.href = "browse.html";
                                    }
                                });
                            }
                        });
                    }
                });

                $('#save').linkbutton({
                    onClick: function () {
                        Tools.confirm('是否确定修改？', function (result) {
                            if (result) {
                                var isValid = $('#form').form("validate");
                                if (isValid) {
                                    var formData = $("#form").serializeJson();
                                    Network.connect(window.api.thSysNavigationUpdateView, "POST", formData, function (res) {
                                        if (res.code === ResponseCode.OK) {
                                            Tools.show(res.message);
                                            parent.location.href = "browse.html";
                                        }
                                    })
                                }
                            }
                        });

                    }
                });

                $('#clean').linkbutton({
                    onClick: function () {
                        ajax.setFormVal();
                    }
                });

            },
            showDialog: function () {
                console.log(count++);
                dlg = window.parent.$.hDialog({
                    href: window.router.menuForm + '?n=' + Math.random(),
                    title: '菜单列表',
                    width: 700,
                    height: 360,
                    showBtns: false,
                    onLoad: function () {
                        Network.connect(window.api.getMenuTree, "POST", {}, function (res) {
                            if (res.code === ResponseCode.OK) {
                                window.parent.$('#menu_tree').tree({
                                    data: res.data,
                                    onClick: function (node) {
                                        $("#pcode").val(node.code);
                                        $("#pname").textbox("setValue", node.text);
                                        dlg.dialog('close');
                                    }
                                });
                            }
                        });
                    }
                });
            }

        }

    </script>

</head>

<body>
<div class="box">
    <form id="form">
        <div style="margin-left: 20px;margin-top: 10px">
            <div class="bar-btn">
                <a id="addTopMenu" data-options="width: 150,height:30" href="#" class="easyui-linkbutton btn-primary">添加顶级菜单</a>
                <a id="addChildMenu" data-options="width: 150,height:30" href="#" class="easyui-linkbutton btn-primary">添加下级菜单</a>
                <a id="delete" data-options="width: 150,height:30" href="#"
                   class="easyui-linkbutton btn-danger">删除</a>
            </div>
        </div>
        <div class="divider"></div>

        <table style="margin-left: 60px">
            <tr>
                <td>
                    <input type="hidden" name="id" id="id"/>
                    <input type="text" class="easyui-textbox" name="code" id="code"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '菜单编号:',
                                                        required: true,
                                                        validType: 'validCode',"/>
                    <span class="text-info">数字、英文字母或者下划线组成的字符串，具有唯一性</span>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" class="easyui-textbox" name="name" id="name"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '菜单名称:',
                                                        required: true,
                                                        validType: 'length[2,50]',"/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" class="easyui-textbox" name="iconCls" id="iconCls"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '菜单图片:',
                                                        required: true,
                                                        validType: 'length[2,50]',"/>

                </td>
            </tr>
            <tr>
                <td>
                    <input type="hidden" name="pcode" id="pcode"/>
                    <input type="text" class="easyui-textbox" name="pname" id="pname"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '上级菜单:',
                                                        required: true,
                                                        validType: 'length[2,50]',"/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" class="easyui-textbox" name="orderNo" id="orderNo"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '菜单排序:',
                                                        required: true,
                                                        validType: 'length[1,999]',"/>
                    <span class="text-info">用于同级菜单排序，值越小越靠前(数值范围：1-999 整数)</span>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" class="easyui-textbox" name="state" id="state"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '默认展示:',
                                                        required: true,
                                                        validType: 'length[2,50]',"/>
                    <span class="text-info">用于树状列表，默认是否展开，显示子菜单</span>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" class="easyui-textbox" name="enable" id="enable"
                           data-options="   width: 400,
                                                        labelWidth:100,
                                                        labelPosition: 'left',
                                                        label: '是否可用:',
                                                        required: true,
                                                        validType: 'length[2,50]',"/>
                </td>
            </tr>
        </table>

        <input type="hidden" name="currentCallback"/>

        <input type="hidden" name="callback_fn" value="queryLeftMenus"/>
        <div class="bottom-btn" style="margin-left: 60px">
            <a id="save" data-options="width: 150,height:30" href="#" class="easyui-linkbutton btn-primary">保存</a>
        <a id="clean" data-options="width: 150,height:30" href="#" class="easyui-linkbutton btn-normal">清空</a>
</div>
    </form>
</div>
</body>
</html>